package ${packageValue}.controller;

import ${packageValue}.dto.${entityName}Dto;
import ${packageValue}.query.${entityName}Query;
import ${packageValue}.service.${entityName}Service;
import ${packageValue}.vo.${entityName}Vo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yupaits.yutool.commons.annotation.ActionLog;
import com.yupaits.yutool.commons.annotation.NoApiLog;
import com.yupaits.yutool.commons.result.Result;
import com.yupaits.yutool.orm.mybatis.annotation.PageQueryDefault;
import com.yupaits.yutool.orm.mybatis.support.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ${comment}接口
 * @author ${author}
 * @since ${date}
 */
@RestController
@RequestMapping("/${apiPath}")
@RequiredArgsConstructor
public class ${entityName}Controller {
    private final ${entityName}Service ${entityObj}Service;

    /**
     * 获取${comment}分页信息
     * @param pageQuery 分页查询参数
     * @param query ${comment}查询对象
     * @return ${comment}分页信息
     */
    @NoApiLog
    @GetMapping("/page")
    public Result<IPage<${entityName}Vo>> page(@PageQueryDefault PageQuery<${entityName}Query> pageQuery, ${entityName}Query query) {
        pageQuery.setQuery(query);
        return Result.ok(${entityObj}Service.page(pageQuery));
    }

    /**
     * 获取${comment}列表
     * @param query ${comment}查询对象
     * @return ${comment}列表
     */
    @NoApiLog
    @GetMapping("/list")
    public Result<List<${entityName}Vo>> list(${entityName}Query query) {
        return Result.ok(${entityObj}Service.list(query));
    }

    /**
     * 保存${comment}
     * @param dto ${comment}Dto对象
     * @return 处理结果
     */
    @ActionLog("保存${comment}")
    @PostMapping("")
    public Result save(@RequestBody ${entityName}Dto dto) {
        ${entityObj}Service.save(dto);
        return Result.ok();
    }

    /**
     * 获取${comment}详情
     * @param id ${comment}ID
     * @return ${comment}详情
     */
    @NoApiLog
    @GetMapping("/{id}")
    public Result<${entityName}Vo> details(@PathVariable Long id) {
        return Result.ok(${entityObj}Service.details(id));
    }

    /**
     * 删除${comment}
     * @param id ${comment}ID
     * @return 处理结果
     */
    @ActionLog("删除${comment}")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id) {
        ${entityObj}Service.deleteById(id);
        return Result.ok();
    }
}